package easy;

/**
 * @author admin
 * 1768. 交替合并字符串
 * 解题思路：直接上for循环，判断条件是小于最长的那个字符串，定义一个count用来标记当前位
 * 置，先添加第一个，然后把count加一，再添加第二个，知道i大于最长的字符串的长度
 */
public class LeeCode1768 {

    public String mergeAlternately(String word1, String word2) {

        int length1 = word1.length();
        int length2 = word2.length();
        int count = 0;
        char[] res = new char[length1 + length2];
        for (int i = 0; i < length1 || i < length2; i++) {
            if (i < length1){
                res[count] = word1.charAt(i);
                count++;
            }
            if (i < length2){
                res[count] = word2.charAt(i);
                count++;
            }
        }

        return new String(res);
    }

    public static void main(String[] args) {
        System.out.println(new LeeCode1768().mergeAlternately("ABC", "def"));
    }
}
